/**
 * 
 */
package model;

import javax.cim.CIMInstance;

/**
 * This class represent an IPSecPolicy on the client side
 * @author alith
 */
public class IPSecPolicy extends CIMObject {

	private String name;
	private String source;
	private String destination;
	private String protocol;
	private String direction;
	private String action;
	private String tunnel_in;
	private String tunnel_out;
	private String type;
	private String transport_type;
	private String level;
	private CIMServer server;
	
	/**
	 * Create a IPSecPolicy WITHOUT registering it on any server
	 * @param name the name of the IPSecPolicy, not saved in the cimserver
	 * @param source the source of the IPSecPolicy,
	 * @param destination the destination of the IPSecPolicy,
	 * @param protocol the protocol of the IPSecPolicy,
	 * @param direction the direction of the IPSecPolicy,
	 * @param action the action of the IPSecPolicy,
	 * @param tunnel_in the tunnel_in of the IPSecPolicy,
	 * @param tunnel_out the tunnel_out of the IPSecPolicy,
	 * @param type the type of the IPSecPolicy,
	 * @param transport_type the transport_type of the IPSecPolicy,
	 * @param level the level of the IPSecPolicy,
	 * @param server the server in which the IPSecPolicy will eventually be stored
	 * @throws CIMBadArgument if any parameter is null or empty or not correct.
	 */
    public IPSecPolicy(String name,String source, String destination, String protocol, String direction, String action, String tunnel_in, String tunnel_out, String type, String transport_type, String level, CIMServer server)  throws CIMBadArgument{
        this.name = name;
        this.source = source;
        this.destination = destination;
        this.protocol = protocol;
        this.direction = direction;
        this.action = action;
        this.tunnel_in = tunnel_in;
        this.tunnel_out = tunnel_out;
        this.type = type;
        this.transport_type = transport_type;
        this.level = level;
        this.server = server;
    }

    /**
     * Create an empty IPSecPolicy, only with the server on which it will eventually be stored.
     * @param server the server in which the IPSecPolicy will eventually be stored
     * @throws CIMBadArgument if any parameter is null or empty or not correct.
     */
    public IPSecPolicy(CIMServer server)  throws CIMBadArgument {
        this.server = server;
    }

    /**
     * Create an IPSecPolicy with an CIMInstance (ie a result from a request on the server)
     * @param inst the CIMInstance of the IPSecPolicy to create
     * @param numero a number to identify this IPSecPolicy (to create an unique name)
     * @param server the server in which this new IPSecPolicy will eventually be stored.
     */
    public IPSecPolicy(CIMInstance inst,int numero, CIMServer server) {
    	this.name = "regle n°"+numero;//n'a aucun sens mais thomas le demande...
        this.source = (String) inst.getProperty("source").getValue();
        this.destination = (String) inst.getProperty("destination").getValue();
        this.protocol = (String) inst.getProperty("protocol").getValue();
        this.direction = (String) inst.getProperty("direction").getValue();
        this.action = (String) inst.getProperty("action").getValue();
        this.tunnel_in = (String) inst.getProperty("tunnel_in").getValue();
        this.tunnel_out = (String) inst.getProperty("tunnel_out").getValue();
        this.type = (String) inst.getProperty("type").getValue();
        this.transport_type = (String) inst.getProperty("transport_type").getValue();
        this.level = (String) inst.getProperty("level").getValue();
        this.server = server;
    }
    
	/* (non-Javadoc)
	 * @see model.CIMObject#delete()
	 */
	@Override
	public void delete() throws Exception {
		server.remove(this);
	}

	/* (non-Javadoc)
	 * @see model.CIMObject#modify()
	 */
	@Override
	public void modify() throws Exception {
		server.update(this);
	}

	/* (non-Javadoc)
	 * @see model.CIMObject#register()
	 */
	@Override
	public void register() throws Exception {
		server.register(this);
	}

	/**
	 * getter to the type of the IPSecPolicy
	 * @return the type of the IPSecPolicy
	 */
	public String getType() {
		return type;
	}
	
	/**
	 * setter to the type of the IPSecPolicy
	 * @param type the type of the IPSecPolicy
	 */
	public void setType(String type) {
		this.type = type;
	}
	
	/**
	 * getter to the name of the IPSecPolicy
	 * @return the name of the IPSecPolicy
	 */
	public String getName() {
		return name;
	}

	/**
	 * setter to the name of the IPSecPolicy
	 * @param name the name of the IPSecPolicy
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * getter to the source of the IPSecPolicy
	 * @return the source of the IPSecPolicy
	 */
	public String getSource() {
		return source;
	}

	/**
	 * setter to the source of the IPSecPolicy
	 * @param source the source of the IPSecPolicy
	 */
	public void setSource(String source) {
		this.source = source;
	}

	/**
	 * getter to the destination of the IPSecPolicy
	 * @return the destination of the IPSecPolicy
	 */
	public String getDestination() {
		return destination;
	}
	
	/**
	 * setter to the destination of the IPSecPolicy
	 * @param destination the destination of the IPSecPolicy
	 */
	public void setDestination(String destination) {
		this.destination = destination;
	}

	/**
	 * getter to the protocol of the IPSecPolicy
	 * @return the protocol of the IPSecPolicy
	 */
	public String getProtocol() {
		return protocol;
	}
	
	/**
	 * setter to the protocol of the IPSecPolicy
	 * @param protocol the protocol of the IPSecPolicy
	 */
	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}

	/**
	 * getter to the direction of the IPSecPolicy
	 * @return the direction of the IPSecPolicy
	 */
	public String getDirection() {
		return direction;
	}
	
	/**
	 * setter to the direction of the IPSecPolicy
	 * @param direction the direction of the IPSecPolicy
	 */
	public void setDirection(String direction) {
		this.direction = direction;
	}

	/**
	 * getter to the action of the IPSecPolicy
	 * @return the action of the IPSecPolicy
	 */
	public String getAction() {
		return action;
	}
	
	/**
	 * setter to the action of the IPSecPolicy
	 * @param action the action of the IPSecPolicy
	 */
	public void setAction(String action) {
		this.action = action;
	}

	/**
	 * getter to the tunnel_in of the IPSecPolicy
	 * @return the tunnel_in of the IPSecPolicy
	 */
	public String getTunnel_in() {
		return tunnel_in;
	}
	
	/**
	 * setter to the tunnel_in of the IPSecPolicy
	 * @param tunnelIn the tunnel_in of the IPSecPolicy
	 */
	public void setTunnel_in(String tunnelIn) {
		tunnel_in = tunnelIn;
	}

	/**
	 * getter to the tunnel_out of the IPSecPolicy
	 * @return the tunnel_out of the IPSecPolicy
	 */
	public String get_tunnel_out() {
		return tunnel_out;
	}
	
	/**
	 * setter to the tunnel_out of the IPSecPolicy
	 * @param tunnelOut the tunnel_out of the IPSecPolicy
	 */
	public void set_tunnel_out(String tunnelOut) {
		tunnel_out = tunnelOut;
	}

	/**
	 * getter to the transport_type of the IPSecPolicy
	 * @return the transport_type of the IPSecPolicy
	 */
	public String getTransport_type() {
		return transport_type;
	}
	
	/**
	 * setter to the transport_type of the IPSecPolicy
	 * @param transportType the transport_type of the IPSecPolicy
	 */
	public void setTransport_type(String transportType) {
		transport_type = transportType;
	}

	/**
	 * getter to the level of the IPSecPolicy
	 * @return the level of the IPSecPolicy
	 */
	public String getLevel() {
		return level;
	}
	
	/**
	 * setter to the level of the IPSecPolicy
	 * @param level the level of the IPSecPolicy
	 */
	public void setLevel(String level) {
		this.level = level;
	}
	
	/* (non-Javadoc)
	 * @see object#toString()
	 */
	@Override
	public String toString() {
		return "regle:"+name+" source:"+source+" destination:"+destination+" protocol="+protocol+" direction="+direction+" action="+action+" tunnel_in="+tunnel_in+" tunnel_out="+tunnel_out+" type="+type+" transport_type="+transport_type+" level="+level;
	}
}
